import axios from "axios";
import {message} from "ant-design-vue";

const _axios = axios.create({
    baseURL: import.meta.env.VITE_BACKEND_API_BASE_URL
});
_axios.interceptors.request.use(
    (config) => {
        (config.headers) = {
            "Authorization": 'aa'
        }
        return config;
    },
    (error) => Promise.reject(error)
)
_axios.interceptors.response.use(
    (response) => {
        if (response.data.message) {
            message.success(response.data.message, 3)
        }
        if (response.data.code === 200) {
            return response
        }
    }
    ,
    (error) => {
        console.error(error)
        if (error.response.status === 400) {
            // window.location.href = '/login'
        } else if (error.response.status === 401) {
            // window.location.href = '/login'
        } else if (error.response.status === 403) {
            // window.location.href = '/login'
        }
        return Promise.resolve({});
        // Promise.reject(error)
    }
)
export default _axios
